<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Service_model extends CI_Model {

	function __construct() {
		parent::__construct();
		$this->load->library('LogSql');
	}

	/**
	 * 운세 서비스 리스트 가져오기
	 */
	function select_service_list() {
		log_message('debug',"## Service_model::select_service_list()");

		$sql  = PHP_EOL." SELECT ";
		$sql .= PHP_EOL."       S.idx ";
		$sql .= PHP_EOL."     , S.service_group_id ";
		$sql .= PHP_EOL."     , S.service_id ";
		$sql .= PHP_EOL."     , S.service_name ";
		$sql .= PHP_EOL."     , S.package_cd ";
		$sql .= PHP_EOL."     , P.package_name ";
		$sql .= PHP_EOL."     , S.price ";
		$sql .= PHP_EOL."     , S.price_vat ";
		$sql .= PHP_EOL."     , S.service_url ";
		$sql .= PHP_EOL."     , S.create_dt ";
		$sql .= PHP_EOL."     , S.update_dt ";
		$sql .= PHP_EOL." FROM  tb_service S, tb_package P ";
		$sql .= PHP_EOL." WHERE S.package_cd = P.package_cd ";
		$sql .= PHP_EOL." ORDER BY S.service_group_id, S.service_id ";
		$query = $this->db->query($sql) or $this->logsql->log_sql('error');
		$result = $query->result_array();
		
		$this->logsql->log_sql();
		$this->logsql->log_result($result);

		return $result;
	}

	/**
	 * 가입상품 코드 리스트
	 */
	function select_package_list() {
		log_message('debug',"## Service_model::select_premium_list()");

		$query = $this->db->get('tb_package') or $this->logsql->log_sql('error');
		$result = $query->result_array();
		
		$this->logsql->log_sql();
		$this->logsql->log_result($result);

		return $result;
	}
	
	// 서비스 정보 업데이트
	function update_service($service) {
		log_message('debug',"## Service_model::update_service($service)");

		$this->db->set('update_dt', 'now()', FALSE);
		$this->db->where('idx', $service['idx']);
		$this->db->update('tb_service', $service) or $this->logsql->log_sql('error');
		
		$this->logsql->log_sql();
	}

	// 서비스 등록
	function insert_service($service) {
		log_message('debug',"## Service_model::insert_service($service)");

		$this->db->set('create_dt', 'now()', FALSE);
		$this->db->set('update_dt', 'now()', FALSE);
		$this->db->insert('tb_service', $service) or $this->logsql->log_sql('error');
		
		$this->logsql->log_sql();
	}

}

/* End of file service_model.php */
/* Location: ./application/models/admin/service_model.php */